// packageF/stockService/components/takeGoods/index.js
Component({
  options: {
    styleIsolation: 'shared' 
  },
  properties: {
    takeGoodsShow: {
      type: Boolean,
      value: false,
    },
    manage_goods: {
      type: null,
      value: {}
    },
    name: {
      type: String,
      value: "",
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    chooseRadio: 1,
    numValue: 1
  },
  lifetimes: {
    attached() {
    },
  },
  observers: {
    'takeGoodsShow'(value) {   // mage 父组件中传过来的可能会进行改变的数据 如果进行改变的话，就继续执行
      if(value) {
        this.setData({
          chooseRadio: this.data.manage_goods.original.show ? 1 : this.data.manage_goods.product.show ? 2 : "",
        });
      }
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      this.setData({
        chooseRadio: event.detail,
      });
    },
    closePopup() {
      this.setData({
        takeGoodsShow: false,
      });
    },
    delivery() {
      let json_data = {
        goodsId: this.data.chooseRadio == 1 ? this.data.manage_goods.original.goods_id : this.data.manage_goods.product.goods_id,
        total: this.data.numValue,
        stock_token: this.data.manage_goods.stock_token,
        take_type: this.data.chooseRadio,
        tag: "stock_service",
        take_way: this.data.name == '代销管理' ? 2 : this.data.name == '我的存货' ? 1 : '',
        option_id: this.data.chooseRadio == 1 ? this.data.manage_goods.original.option_id : this.data.manage_goods.product.option_id, 
      };
      wx.navigateTo({
        url: `/packageD/buy/myOrder_v2/myOrder_v2?tag=stock_service&total=${json_data.total}&take_way=${json_data.take_way}&take_type=${json_data.take_type}&stock_token=${json_data.stock_token}&goodsId=${json_data.goodsId}&option_id=${json_data.option_id}`
      });
      this.setData({
        takeGoodsShow: false,
      });
    },
    onChangeStepper(event) {
      this.setData({
        numValue: event.detail
      })
    }
  }
})
